<%@ page import="com.biz.conf.Global" %>
<%@ include file="/jsp/taglib.jsp"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>信息编辑窗体</title>
    <meta name="keywords" content="">
    <meta name="description" content="">


    <link rel="shortcut icon" href="favicon.ico">
    <link href="${ctxStatic}/plugins/h+/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/animate.min.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="${ctxStatic}/plugins/h+/css/plugins/webuploader/webuploader.css">
    <link href="${ctxStatic}/plugins/h+/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">

    <link href="${ctxStatic}/plugins/h+/css/font-awesome.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/chosen/chosen.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/colorpicker/css/bootstrap-colorpicker.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/cropper/cropper.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/switchery/switchery.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/jasny/jasny-bootstrap.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/nouslider/jquery.nouislider.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/datapicker/datepicker3.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/ionRangeSlider/ion.rangeSlider.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/ionRangeSlider/ion.rangeSlider.skinFlat.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/clockpicker/clockpicker.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/animate.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/style.min.css?v=4.0.0" rel="stylesheet"><base target="_blank">
    <link href="${pageContext.request.contextPath}/resources/plugins/h+/css/plugins/jsTree/style.min.css" rel="stylesheet">
    <style>
        .fileInputContainer{
            width: 150px;
            background-size: 100% 100%;
            height: 150px;
            background-repeat: no-repeat;
        }
        .fileInput{
            position: absolute;
            top:30%;
            left:30%;
        }.upload_pic {
             height: 70px;
             width:70px;
             position: relative;
             cursor: pointer;
             color: #ccbe9e;
             background: #fff;
             overflow: hidden;
             display: inline-block;
             *display: inline;
             *zoom: 1;
         }
        .upload_pic input {
            position: absolute;
            height:100%;
            width:100%;
            right: 0;
            top: 0;
            opacity: 0;
            filter: alpha(opacity=0);
            cursor: pointer
        }
        .upload_pic:hover {
            color: #ccbe9e;
            background: #fff;
            text-decoration: none
        }      .chosen-container{
                   width:100% !important;
               }
    </style>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
              <%--  <div class="ibox-title">
                    <h5>用户管理</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                    </div>
                </div>--%>
                <div class="ibox-content">
                    <form onsubmit="return  false" class="form-horizontal m-t" id="signupForm">
                        <input id="sysUser_id" value="${sysUser.user_code}" name="sysUser.user_code" type="hidden">
                        <input id="sysUser_identity_code" value="${sysUser.identity_code}" name="sysUser.identity_code" type="hidden">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">头像：</label>
                            <div class="col-sm-8">
                                <input type="hidden" id="picid2" value="${sysUser.pic_url}" name="sysUser.pic_url">
                                <div class="dtupload">
                                    <a href="javascript:" class="upload_pic" style="height:80px;"><input type="file" name="fileToUpload" id="upfile2" onChange="uploadFileEidt('upfile2','f03');">
                                        <img class="img-circle" id="f03" src="${sysUser.pic_url}" width="100%"  height="100%"/>
                                    </a>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">用户类型：</label>
                            <div class="col-sm-8">
                                <select data-placeholder="用户类型" class="chosen-select form-control" name="sysUser.identity" value="${sysUser.identity}" id="sysUser_identity">
                                    <option value="">请选择</option>
                                    <option value="1">管理</option>
                                    <option value="2">品牌</option>
                                    <option value="3">商户</option>
                                    <option value="4">门店</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group" id="agentDiv" style="display: none">
                            <label class="col-sm-3 control-label">所属品牌：</label>
                            <div class="col-sm-8">
                                <select data-placeholder="所属品牌" class="chosen-select form-control" id="agentId" >

                                </select>
                            </div>
                        </div>
                        <div class="form-group" id="brandDiv" style="display: none">
                            <label class="col-sm-3 control-label">所属商户：</label>
                            <div class="col-sm-8">
                                <select data-placeholder="所属商户" class="chosen-select form-control" id="brandId" >

                                </select>
                            </div>
                        </div>
                        <div class="form-group" id="shopDiv" style="display: none">
                            <label class="col-sm-3 control-label">所属门店：</label>
                            <div class="col-sm-8">
                                <select data-placeholder="所属门店" class="chosen-select form-control"  id="shopId" >
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">登陆名：</label>
                            <div class="col-sm-8">
                                <input id="sysUser_loginName" value="${sysUser.login_name}" name="sysUser.login_name" class="form-control" type="text" aria-required="true" aria-invalid="true" class="error">
                                <c:if test="${id =='' || id ==null}">
                                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 密码默认和用户名相同</span>
                                </c:if>
                            </div>
                        </div>
                       <%-- <div class="form-group">
                            <label class="col-sm-3 control-label">密码：</label>
                            <div class="col-sm-8">
                                <input id="sysUser_pwd" value="${user.pwd}" name="sysUser.pwd" class="form-control" type="password">
                            </div>
                        </div>--%>
                      <%--  <div class="form-group">
                            <label class="col-sm-3 control-label">确认密码：</label>
                            <div class="col-sm-8">
                                <input id="confirm_password" name="confirm_password" class="form-control" type="password">
                                <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 请再次输入您的密码</span>
                            </div>
                        </div>--%>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">姓名：</label>
                            <div class="col-sm-8">
                                <input id="sysUser_personName" value="${sysUser.person_name}" name="sysUser.person_name" class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">手机号码：</label>
                            <div class="col-sm-8">
                                <input id="sysUser_phone" value="${sysUser.phone}" name="sysUser.phone" class="form-control" type="phone" aria-required="true" aria-invalid="false" class="valid">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">邮箱：</label>
                            <div class="col-sm-8">
                                <input id="sysUser_email" value="${sysUser.email}" name="sysUser.email" class="form-control" type="email">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">备注：</label>
                            <div class="col-sm-8">
                                <input id="sysUser_notes" value="${sysUser.notes}" name="sysUser.notes" class="form-control" type="text">
                            </div>
                        </div>
                        <input id="sysUser_sorts" value="99" name="sysUser.sorts" class="form-control" type="hidden">

                    <%--       <div class="form-group">
                            <label class="col-sm-3 control-label">排序：</label>
                            <div class="col-sm-8">
                                <input id="sysUser_sorts" value="99" value="${sysUser.sort}" name="sysUser.sort" class="form-control" type="number">
                            </div>
                        </div>--%>
                     <%--   <div class="form-group" id="div_sp">
                            <label class="col-sm-3 control-label">审批：</label>
                            <div class="col-sm-8">
                                <select data-placeholder="用户审批" class="chosen-select form-control" name="sysUser.state" value="${sysUser.state}"  >
                                    <option value="1">审批通过</option>
                                    <option value="2">退回</option>
                                </select>
                            </div>
                        </div>--%>
                        <div class="form-group">
                            <div class="col-sm-8 col-sm-offset-3">
                                <button class="btn btn-primary" onclick="doSubmit();">提交</button>
                                <button id="btn_close"  class="btn btn-primary" type="button">关闭</button>
                                <%--<button id="transmit"  class="btn btn-primary" type="button">给父页面传值</button>--%>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<%--<script src="${pageContext.request.contextPath}/resources/plugins/h+/js/jquery.min.js?v=2.1.4"></script>
<script src="${pageContext.request.contextPath}/resources/plugins/h+/js/bootstrap.min.js?v=3.3.6"></script>
<script src="${pageContext.request.contextPath}/resources/plugins/h+/js/content.min.js?v=1.0.0"></script>
<script src="${pageContext.request.contextPath}/resources/plugins/h+/js/plugins/validate/jquery.validate.min.js"></script>
<script src="${pageContext.request.contextPath}/resources/plugins/h+/js/plugins/validate/messages_zh.min.js"></script>
<script src="${pageContext.request.contextPath}/resources/plugins/h+/js/demo/form-validate-demo.min.js"></script>
<script src="${pageContext.request.contextPath}/resources/plugins/h+/js/plugins/layer2.4/layer.js"></script>
<script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/chosen/chosen.jquery.js"></script>--%>

<script src="${ctxStatic}/plugins/h+/js/jquery.min.js?v=2.1.4"></script>
<script src="${ctxStatic}/plugins/h+/js/bootstrap.min.js?v=3.3.6"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/bootstrap-table-master/bootstrap-table.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/bootstrap-table-master/locale/bootstrap-table-zh-CN.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/bootstrap-table-master/extensions/export/bootstrap-table-export.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/bootstrap-table-master/extensions/editable/bootstrap-table-editable.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/sweetalert/sweetalert.min.js"></script>
<script src="${ctxStatic}/plugins/h+/js/content.min.js?v=1.0.0"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/chosen/chosen.jquery.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/layer/laydate/laydate.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/plugins/ajaxfileupload.js"></script>

<script>
    var picPath='<%=Global.getConfig("OSSURL")%>';

    var agentId='';
    var brandId='';
    var shopId='';
    $(function(){
        //alert('${param.userCode}');
        var identity='${sysUser.identity}';
        if(2==identity)
        {
            agentId= '${identityInfo.code}';
            $("#brandDiv").hide();
            $("#agentDiv").show();
            $("#shopDiv").hide()
        }else if(3==identity)
        {
            brandId= '${identityInfo.code}';
            agentId='${identityInfo.agent_code}';
            $("#brandDiv").show();
            $("#agentDiv").show();
            $("#shopDiv").hide()
        }else if(4==identity)
        {
            shopId='${identityInfo.code}';
            brandId='${identityInfo.brand_code}';
            agentId='${identityInfo.agent_code}';
            $("#brandDiv").show();
            $("#agentDiv").show();
            $("#shopDiv").show()
        }
        loadAgentList();
        $("#brandId").chosen({
            no_results_text: "未找到此选项!",
            width: "100%"
        });
        $("#shopId").chosen({
            no_results_text: "未找到此选项!",
            width: "100%"
        });
        $("#sysUser_identity").chosen({
            no_results_text: "未找到此选项!",
            width: "100%"
        });
        $("#sysUser_identity").val(identity);
        $("#sysUser_identity").trigger("chosen:updated");

        if('${spType}'=='sp')
        {
            $("#div_sp").show();
        }else
        {
            $("#div_sp").hide();
        }
    });

    $("#sysUser_identity").chosen().change(function () {
        var identity = $("#sysUser_identity").val();
        if(identity==2)
        {
            $("#brandDiv").hide();
            $("#agentDiv").show();
            $("#shopDiv").hide()
        }else if(identity==3)
        {
            $("#brandDiv").show();
            $("#agentDiv").show();
            $("#shopDiv").hide()
        }
        else if(identity==4)
        {
            $("#brandDiv").show();
            $("#agentDiv").show();
            $("#shopDiv").show();
        }else
        {$("#brandDiv").hide();
            $("#agentDiv").hide();
            $("#shopDiv").hide();}
    });

    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
   /* //parent.layer.iframeAuto(index);
    //让层自适应iframe
    $('#add').on('click', function(){
        $('body').append('插入很多酱油。插入很多酱油。插入很多酱油。插入很多酱油。插入很多酱油。插入很多酱油。插入很多酱油。');

    });
    //给父页面传值
    $('#transmit').on('click', function(){

       // parent(".J_iframe").$("#spancc").text("5");
        alert(parent.$('#spancc').text());
        $(parent.window.frames["iframe8"].document).find("#spancc").html("我被改变了");
        $(parent.window.frames["iframe8"].document).find("#exampleTablePagination").bootstrapTable('refresh');
        //parent.$('#spancc').html('我被改变了');
        parent.layer.close(index);
    });*/

    //关闭iframe
    $('#btn_close').click(function(){
        parent.layer.close(index);
    });

    function doSubmit()
    {
        var identity = $("#sysUser_identity").val();
        var loginName=$("#sysUser_loginName").val();
        //var pwd=$("#sysUser_pwd").val();
        var personName=$("#sysUser_personName").val();
        var phone=$("#sysUser_phone").val();
        var email=$("#sysUser_email").val();
        var isOk=true;
        if(identity==null||identity==undefined||identity==''){alert("请选择用户类型");isOk= false;}
      //  if(identity==3&&(profit=='')){alert("请输入红利比例");isOk= false;}
        if(loginName==null||loginName==undefined||loginName==''){alert("请输入登录名");isOk= false;}
      /*  if(pwd==null||pwd==undefined||pwd==''){alert("请输入密码");isOk= false;}*/
        if(personName==null||personName==undefined||personName==''){alert("请输入姓名");isOk= false;}
        if(phone==null||phone==undefined||phone==''){alert("请输入手机号码");isOk= false;}
        //if(email==null||email==undefined||email==''){alert("请输入邮箱");isOk= false;}
        var identityMsg='';
        if(2==identity)
        {
            $("#sysUser_identity_code").val($("#agentId").val());
            identityMsg='请选择品牌';
        }else
        if(3==identity)
        {$("#sysUser_identity_code").val($("#brandId").val());
            identityMsg='请选择商户';}else
        if(4==identity)
        {$("#sysUser_identity_code").val($("#shopId").val());
            identityMsg='请选择门店';}

        var identity_code= $("#sysUser_identity_code").val()
        if(identity_code==null||identity_code==undefined||identity_code==''){alert(identityMsg);isOk= false;}
        if(isOk){
            $.ajax( {
                url:'${pageContext.request.contextPath}/sysUser/doSave.ac',// 跳转到 action
                data:$("#signupForm").serialize(),
                type:'post',
                cache:false,
                dataType:'json',
                success:function(data) {
                    if(data=="success")
                    {
                        alert("操作成功！");

                        parent.layer.close(index);
                    }else{
                        alert(data);
                    }
                },
                error : function() {
                    alert("操作失败！");
                }
            });
        }
    }

    //上传头像
    function uploadFileEidt(obj,pic){
        $.ajaxFileUpload  ({
            url: '${pageContext.request.contextPath}/file/doUploadFile.ac',
            secureuri: false,
            fileElementId: obj,
            dataType: 'json',
            beforeSend: function() {
                //$("#loading").show();
            },
            complete: function() {
                //$("#loading").hide();
            },
            success: function(data, status) {

                var hi=picPath+data.path;
                $("#"+pic).attr("src",hi);
                $("#picid2").attr("value",hi);
            },
            error: function(data, status, e) {
                alert(e);
            }
        });
    }
    
    
    function loadAgentList() {
        var url = "${ctx}/agent/loadAgentList.ac";
        $.ajax({
            url: url,
            data: {},
            type: 'post',
            cache: false,
            dataType: 'json',
            success: function (data) {
                //$("#agentId").chosen("destroy");
                var html = '<option value="">请选择</option>';
                $(data).each(function (index, value) {
                    html += '<option value="' + value.code + '">' + value.name + '</option>';
               });
                $("#agentId").html(html);
               $("#agentId").chosen();
                if (agentId != null && agentId != undefined && agentId != '') {
                    $("#agentId").val(agentId);
                    $("#agentId").trigger("chosen:updated");
                    loadBrandList(agentId)
                }
                $("#brandId").val('');
                $("#shopId").val('');
                $("#agentId").chosen().change(function ()
                {
                    loadBrandList($("#agentId").val());
                }
                );
            },
            error: function () {
                alert("异常！");
            }
        });
    }
    function loadBrandList(pid) {

        var url = "${ctx}/merchant/loadBrandList.ac";
        $.ajax({
            url: url,
            data: {id:pid},
            type: 'post',
            cache: false,
            dataType: 'json',
            success: function (data) {
               // $("#brandId").chosen("destroy");
                var html = '<option value="">请选择</option>';
                $(data).each(function (index, value) {
                    html += '<option value="' + value.code + '">' + value.name + '</option>';
                });
                $("#brandId").html(html);

                $("#shopId").val('');
                $("#shopId").trigger("chosen:updated");
                if (brandId != null && brandId != undefined && brandId != ''&&pid==agentId) {
                    $("#brandId").val(brandId);
                    loadShopList(brandId)
                }
                $("#brandId").trigger("chosen:updated");
                $("#brandId").chosen().change(function ()
                 {
                     loadShopList($("#brandId").val());
                  }
                );
            },
            error: function () {
                alert("异常！");
            }
        });
    }

    function loadShopList(pid) {

        var url = "${ctx}/shop/loadShopList.ac";
        $.ajax({
            url: url,
            data: {id:pid},
            type: 'post',
            cache: false,
            dataType: 'json',
            success: function (data) {
             ///   $("#shopId").chosen("destroy");
                var html = '<option value="">请选择</option>';
                $(data).each(function (index, value) {
                    html += '<option value="' + value.code + '">' + value.business_name + '</option>';
                });
                $("#shopId").html(html);
                if (shopId != null && shopId != undefined && shopId != ''&&pid==brandId) {
                    $("#shopId").val(shopId);
                }
                $("#shopId").trigger("chosen:updated");
            },
            error: function () {
                alert("异常！");
            }
        });
    }
</script>

</body>

</html>

